home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 February: Tool Chest / Dev.CD Feb 00 TC.toast / pc / what's new? / development kits / hardware / mac_os_usb_ddk_v1.4b6 / interfaces / usb.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-21  |  33.5 KB  |  1,301 lines

  1. /*
  2.      File:        USB.h
  3.  
  4.      Contains:    Public API for USB Services Library (and associated components)
  5.  
  6.      Version:    USB 1.3
  7.  
  8. */
  9. #ifndef __USB__
  10. #define __USB__
  11.  
  12. #ifndef __MACTYPES__
  13. #include <MacTypes.h>
  14. #endif
  15.  
  16. #ifndef __NAMEREGISTRY__
  17. #include <NameRegistry.h>
  18. #endif
  19.  
  20. #ifndef __CODEFRAGMENTS__
  21. #include <CodeFragments.h>
  22. #endif
  23.  
  24. #ifndef __DEVICES__
  25. #include <Devices.h>
  26. #endif
  27.  
  28. #ifndef __MACERRORS__
  29. #include <MacErrors.h>
  30. #endif
  31.  
  32.  
  33.  
  34.  
  35. #if PRAGMA_ONCE
  36. #pragma once
  37. #endif
  38.  
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42.  
  43. #if PRAGMA_IMPORT
  44. #pragma import on
  45. #endif
  46.  
  47. #if PRAGMA_STRUCT_ALIGN
  48.     #pragma options align=mac68k
  49. #elif PRAGMA_STRUCT_PACKPUSH
  50.     #pragma pack(push, 2)
  51. #elif PRAGMA_STRUCT_PACK
  52.     #pragma pack(2)
  53. #endif
  54.  
  55. /* ************* Constants ************* */
  56.  
  57. enum {
  58.                                                                 /* Flags */
  59.     kUSBTaskTimeFlag            = 1,
  60.     kUSBHubPower                = 2,
  61.     kUSBPowerReset                = 4,
  62.     kUSBHubReaddress            = 8,
  63.     kUSBAddressRequest            = 16,
  64.     kUSBReturnOnException        = 32,
  65.     kUSBNo5SecTimeout            = 64,
  66.     kUSBTimeout                    = 128,
  67.     kUSBNoDataTimeout            = 256,
  68.     kUSBDebugAwareFlag            = 512
  69. };
  70.  
  71. enum {
  72.                                                                 /* Hub messages */
  73.     kUSBHubPortResetRequest        = 1,
  74.     kUSBHubPortSuspendRequest    = 2,
  75.     kUSBHubPortStatusRequest    = 3
  76. };
  77.  
  78. enum {
  79.     kVendorID_AppleComputer        = 0x05AC
  80. };
  81.  
  82. /* ************* types ************* */
  83.  
  84. typedef SInt32                             USBReference;
  85. typedef USBReference                     USBDeviceRef;
  86. typedef USBDeviceRef *                    USBDeviceRefPtr;
  87. typedef USBReference                     USBInterfaceRef;
  88. typedef USBReference                     USBPipeRef;
  89. typedef USBReference                     USBBusRef;
  90. typedef UInt32                             USBPipeState;
  91. typedef UInt32                             USBCount;
  92. typedef UInt32                             USBFlags;
  93. typedef UInt8                             USBRequest;
  94. typedef UInt8                             USBDirection;
  95. typedef UInt8                             USBRqRecipient;
  96. typedef UInt8                             USBRqType;
  97. typedef UInt16                             USBRqIndex;
  98. typedef UInt16                             USBRqValue;
  99.  
  100.  
  101.  
  102. struct usbControlBits {
  103.     UInt8                             BMRequestType;
  104.     UInt8                             BRequest;
  105.     USBRqValue                         WValue;
  106.     USBRqIndex                         WIndex;
  107.     UInt16                             reserved4;
  108. };
  109. typedef struct usbControlBits            usbControlBits;
  110.  
  111. struct USBIsocFrame {
  112.     OSStatus                         frStatus;
  113.     UInt16                             frReqCount;
  114.     UInt16                             frActCount;
  115. };
  116. typedef struct USBIsocFrame                USBIsocFrame;
  117. enum {
  118.     kUSBMaxIsocFrameReqCount    = 1023                            /* maximum size (bytes) of any one Isoc frame*/
  119. };
  120.  
  121.  
  122. struct usbIsocBits {
  123.     USBIsocFrame *                    FrameList;
  124.     UInt32                             NumFrames;
  125. };
  126. typedef struct usbIsocBits                usbIsocBits;
  127.  
  128. struct usbHubBits {
  129.     UInt32                             Request;
  130.     UInt32                             Spare;
  131. };
  132. typedef struct usbHubBits                usbHubBits;
  133. typedef struct USBPB                     USBPB;
  134. typedef CALLBACK_API_C( void , USBCompletion )(USBPB *pb);
  135.  
  136. union USBVariantBits {
  137.     usbControlBits                     cntl;
  138.     usbIsocBits                     isoc;
  139.     usbHubBits                         hub;
  140. };
  141. typedef union USBVariantBits            USBVariantBits;
  142.  
  143. struct USBPB {
  144.  
  145.     void *                            qlink;
  146.     UInt16                             qType;
  147.     UInt16                             pbLength;
  148.     UInt16                             pbVersion;
  149.     UInt16                             reserved1;
  150.     UInt32                             reserved2;
  151.  
  152.     OSStatus                         usbStatus;
  153.     USBCompletion                     usbCompletion;
  154.     UInt32                             usbRefcon;
  155.  
  156.     USBReference                     usbReference;
  157.  
  158.     void *                            usbBuffer;
  159.     USBCount                         usbReqCount;
  160.     USBCount                         usbActCount;
  161.  
  162.     USBFlags                         usbFlags;
  163.  
  164.     USBVariantBits                     usb;
  165.  
  166.     UInt32                             usbFrame;
  167.  
  168.     UInt8                             usbClassType;
  169.     UInt8                             usbSubclass;
  170.     UInt8                             usbProtocol;
  171.     UInt8                             usbOther;
  172.  
  173.     UInt32                             reserved6;
  174.     UInt16                             reserved7;
  175.     UInt16                             reserved8;
  176.  
  177. };
  178.  
  179.  
  180. typedef USBPB *                            USBPBPtr;
  181. #if !defined(OLDUSBNAMES)
  182. #define OLDUSBNAMES 0
  183. #endif
  184.  
  185. #if OLDUSBNAMES
  186. #define usbBMRequestType  usb.cntl.BMRequestType
  187. #define usbBRequest       usb.cntl.BRequest
  188. #define usbWValue         usb.cntl.WValue
  189. #define usbWIndex         usb.cntl.WIndex
  190. #endif
  191.  
  192. struct uslReq {
  193.     USBDirection                     usbDirection;
  194.     USBRqType                         usbType;
  195.     USBRqRecipient                     usbRecipient;
  196.     USBRequest                         usbRequest;
  197. };
  198. typedef struct uslReq                    uslReq;
  199.  
  200. enum {
  201.                                                                 /* BT 19Aug98, bump up to v1.10 for Isoc*/
  202.     kUSBCurrentPBVersion        = 0x0100,                        /* v1.00*/
  203.     kUSBIsocPBVersion            = 0x0109,                        /* v1.10*/
  204.     kUSBCurrentHubPB            = kUSBIsocPBVersion
  205. };
  206.  
  207.  
  208.  
  209.  
  210. #define kUSBNoCallBack ((USBCompletion)-1L)
  211.  
  212.  
  213. typedef UInt8                             bcdUSB;
  214. enum {
  215.     kUSBControl                    = 0,
  216.     kUSBIsoc                    = 1,
  217.     kUSBBulk                    = 2,
  218.     kUSBInterrupt                = 3,
  219.     kUSBAnyType                    = 0xFF
  220. };
  221.  
  222. /* endpoint type */
  223. enum {
  224.     kUSBOut                        = 0,
  225.     kUSBIn                        = 1,
  226.     kUSBNone                    = 2,
  227.     kUSBAnyDirn                    = 3
  228. };
  229.  
  230. /*USBDirection*/
  231. enum {
  232.     kUSBStandard                = 0,
  233.     kUSBClass                    = 1,
  234.     kUSBVendor                    = 2
  235. };
  236.  
  237. /*USBRqType*/
  238. enum {
  239.     kUSBDevice                    = 0,
  240.     kUSBInterface                = 1,
  241.     kUSBEndpoint                = 2,
  242.     kUSBOther                    = 3
  243. };
  244.  
  245. /*USBRqRecipient*/
  246. enum {
  247.     kUSBRqGetStatus                = 0,
  248.     kUSBRqClearFeature            = 1,
  249.     kUSBRqReserved1                = 2,
  250.     kUSBRqSetFeature            = 3,
  251.     kUSBRqReserved2                = 4,
  252.     kUSBRqSetAddress            = 5,
  253.     kUSBRqGetDescriptor            = 6,
  254.     kUSBRqSetDescriptor            = 7,
  255.     kUSBRqGetConfig                = 8,
  256.     kUSBRqSetConfig                = 9,
  257.     kUSBRqGetInterface            = 10,
  258.     kUSBRqSetInterface            = 11,
  259.     kUSBRqSyncFrame                = 12
  260. };
  261.  
  262. /*USBRequest*/
  263.  
  264. enum {
  265.     kUSBDeviceDesc                = 1,
  266.     kUSBConfDesc                = 2,
  267.     kUSBStringDesc                = 3,
  268.     kUSBInterfaceDesc            = 4,
  269.     kUSBEndpointDesc            = 5,
  270.     kUSBHIDDesc                    = 0x21,
  271.     kUSBReportDesc                = 0x22,
  272.     kUSBPhysicalDesc            = 0x23,
  273.     kUSBHUBDesc                    = 0x29
  274. };
  275.  
  276. /* descriptorType */
  277.  
  278. enum {
  279.     kUSBFeatureDeviceRemoteWakeup = 1,
  280.     kUSBFeatureEndpointStall    = 0
  281. };
  282.  
  283. /* Feature selectors */
  284. enum {
  285.     kUSBActive                    = 0,                            /* Pipe can accept new transactions*/
  286.     kUSBIdle                    = 1,                            /* Pipe will not accept new transactions*/
  287.     kUSBStalled                    = 2,                            /* An error occured on the pipe*/
  288.     kUSBSuspended                = 4,                            /* Device is suspended*/
  289.     kUSBNoBandwidth                = 8                                /* (Isoc or Int) Pipe could not be initialised due to bandwidth constraint*/
  290. };
  291.  
  292. enum {
  293.     kUSB100mAAvailable            = 50,
  294.     kUSB500mAAvailable            = 250,
  295.     kUSB100mA                    = 50,
  296.     kUSBAtrBusPowered            = 0x80,
  297.     kUSBAtrSelfPowered            = 0x40,
  298.     kUSBAtrRemoteWakeup            = 0x20
  299. };
  300.  
  301. enum {
  302.     kUSBRel10                    = 0x0100
  303. };
  304.  
  305. #define USB_CONSTANT16(x)    ((((x) >> 8) & 0x0ff) | ((x & 0xff) << 8))
  306. enum {
  307.     kUSBDeviceDescriptorLength    = 0x12,
  308.     kUSBInterfaceDescriptorLength = 0x09,
  309.     kUSBConfigDescriptorLength    = 0x09
  310. };
  311.  
  312.  
  313. struct USBDeviceDescriptor {
  314.     UInt8                             length;
  315.     UInt8                             descType;
  316.     UInt16                             usbRel;
  317.     UInt8                             deviceClass;
  318.     UInt8                             deviceSubClass;
  319.     UInt8                             protocol;
  320.     UInt8                             maxPacketSize;
  321.     UInt16                             vendor;
  322.     UInt16                             product;
  323.     UInt16                             devRel;
  324.     UInt8                             manuIdx;
  325.     UInt8                             prodIdx;
  326.     UInt8                             serialIdx;
  327.     UInt8                             numConf;
  328. };
  329. typedef struct USBDeviceDescriptor        USBDeviceDescriptor;
  330. typedef USBDeviceDescriptor *            USBDeviceDescriptorPtr;
  331. #ifndef OLDCLASSNAMES
  332. #ifndef __cplusplus
  333. #define class deviceClass
  334. #define subClass deviceSubClass
  335. #endif
  336. #endif
  337.  
  338.  
  339.  
  340. struct USBDescriptorHeader {
  341.     UInt8                             length;
  342.     UInt8                             descriptorType;
  343. };
  344. typedef struct USBDescriptorHeader        USBDescriptorHeader;
  345. typedef USBDescriptorHeader *            USBDescriptorHeaderPtr;
  346.  
  347. struct USBConfigurationDescriptor {
  348.     UInt8                             length;
  349.     UInt8                             descriptorType;
  350.     UInt16                             totalLength;
  351.     UInt8                             numInterfaces;
  352.     UInt8                             configValue;
  353.     UInt8                             configStrIndex;
  354.     UInt8                             attributes;
  355.     UInt8                             maxPower;
  356. };
  357. typedef struct USBConfigurationDescriptor USBConfigurationDescriptor;
  358. typedef USBConfigurationDescriptor *    USBConfigurationDescriptorPtr;
  359.  
  360. struct USBInterfaceDescriptor {
  361.     UInt8                             length;
  362.     UInt8                             descriptorType;
  363.     UInt8                             interfaceNumber;
  364.     UInt8                             alternateSetting;
  365.     UInt8                             numEndpoints;
  366.     UInt8                             interfaceClass;
  367.     UInt8                             interfaceSubClass;
  368.     UInt8                             interfaceProtocol;
  369.     UInt8                             interfaceStrIndex;
  370. };
  371. typedef struct USBInterfaceDescriptor    USBInterfaceDescriptor;
  372. typedef USBInterfaceDescriptor *        USBInterfaceDescriptorPtr;
  373.  
  374. struct USBEndPointDescriptor {
  375.     UInt8                             length;
  376.     UInt8                             descriptorType;
  377.     UInt8                             endpointAddress;
  378.     UInt8                             attributes;
  379.     UInt16                             maxPacketSize;
  380.     UInt8                             interval;
  381. };
  382. typedef struct USBEndPointDescriptor    USBEndPointDescriptor;
  383. typedef USBEndPointDescriptor *            USBEndPointDescriptorPtr;
  384.  
  385. struct USBHIDDescriptor {
  386.     UInt8                             descLen;
  387.     UInt8                             descType;
  388.     UInt16                             descVersNum;
  389.     UInt8                             hidCountryCode;
  390.     UInt8                             hidNumDescriptors;
  391.     UInt8                             hidDescriptorType;
  392.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  393.     UInt8                             hidDescriptorLengthHi;
  394. };
  395. typedef struct USBHIDDescriptor            USBHIDDescriptor;
  396. typedef USBHIDDescriptor *                USBHIDDescriptorPtr;
  397.  
  398. struct USBHIDReportDesc {
  399.     UInt8                             hidDescriptorType;
  400.     UInt8                             hidDescriptorLengthLo;        /* can't make this a single 16bit value or the compiler will add a filler byte*/
  401.     UInt8                             hidDescriptorLengthHi;
  402. };
  403. typedef struct USBHIDReportDesc            USBHIDReportDesc;
  404. typedef USBHIDReportDesc *                USBHIDReportDescPtr;
  405.  
  406. struct USBHubPortStatus {
  407.     UInt16                             portFlags;                    /* Port status flags */
  408.     UInt16                             portChangeFlags;            /* Port changed flags */
  409. };
  410. typedef struct USBHubPortStatus            USBHubPortStatus;
  411. typedef USBHubPortStatus *                USBHubPortStatusPtr;
  412. /* ********* ProtoTypes *************** */
  413. /* For dealing with endianisms */
  414. #if CALL_NOT_IN_CARBON
  415. EXTERN_API_C( UInt16 )
  416. HostToUSBWord                    (UInt16                 value);
  417.  
  418. EXTERN_API_C( UInt16 )
  419. USBToHostWord                    (UInt16                 value);
  420.  
  421. EXTERN_API_C( UInt32 )
  422. HostToUSBLong                    (UInt32                 value);
  423.  
  424. EXTERN_API_C( UInt32 )
  425. USBToHostLong                    (UInt32                 value);
  426.  
  427. /* Main prototypes */
  428. /* Transfer commands */
  429. EXTERN_API_C( OSStatus )
  430. USBDeviceRequest                (USBPB *                pb);
  431.  
  432. EXTERN_API_C( OSStatus )
  433. USBBulkWrite                    (USBPB *                pb);
  434.  
  435. EXTERN_API_C( OSStatus )
  436. USBBulkRead                        (USBPB *                pb);
  437.  
  438. EXTERN_API_C( OSStatus )
  439. USBIntRead                        (USBPB *                pb);
  440.  
  441. EXTERN_API_C( OSStatus )
  442. USBIntWrite                        (USBPB *                pb);
  443.  
  444. EXTERN_API_C( OSStatus )
  445. USBIsocRead                        (USBPB *                pb);
  446.  
  447. EXTERN_API_C( OSStatus )
  448. USBIsocWrite                    (USBPB *                pb);
  449.  
  450. /* Pipe state control */
  451. EXTERN_API_C( OSStatus )
  452. USBClearPipeStallByReference    (USBPipeRef             ref);
  453.  
  454. EXTERN_API_C( OSStatus )
  455. USBAbortPipeByReference            (USBReference             ref);
  456.  
  457. EXTERN_API_C( OSStatus )
  458. USBResetPipeByReference            (USBReference             ref);
  459.  
  460. EXTERN_API_C( OSStatus )
  461. USBSetPipeIdleByReference        (USBPipeRef             ref);
  462.  
  463. EXTERN_API_C( OSStatus )
  464. USBSetPipeActiveByReference        (USBPipeRef             ref);
  465.  
  466. EXTERN_API_C( OSStatus )
  467. USBClosePipeByReference            (USBPipeRef             ref);
  468.  
  469. EXTERN_API_C( OSStatus )
  470. USBGetPipeStatusByReference        (USBReference             ref,
  471.                                  USBPipeState *            state);
  472.  
  473.  
  474. /* Configuration services */
  475. EXTERN_API_C( OSStatus )
  476. USBFindNextInterface            (USBPB *                pb);
  477.  
  478. EXTERN_API_C( OSStatus )
  479. USBOpenDevice                    (USBPB *                pb);
  480.  
  481. EXTERN_API_C( OSStatus )
  482. USBSetConfiguration                (USBPB *                pb);
  483.  
  484. EXTERN_API_C( OSStatus )
  485. USBNewInterfaceRef                (USBPB *                pb);
  486.  
  487. EXTERN_API_C( OSStatus )
  488. USBDisposeInterfaceRef            (USBPB *                pb);
  489.  
  490. EXTERN_API_C( OSStatus )
  491. USBConfigureInterface            (USBPB *                pb);
  492.  
  493. EXTERN_API_C( OSStatus )
  494. USBFindNextPipe                    (USBPB *                pb);
  495.  
  496. #endif  /* CALL_NOT_IN_CARBON */
  497.  
  498. #if CALL_NOT_IN_CARBON
  499. EXTERN_API_C( OSStatus )
  500. USBSetPipePolicy                (USBPB *                pb);
  501.  
  502. #endif  /* CALL_NOT_IN_CARBON */
  503.  
  504. /* Dealing with descriptors. */
  505. /* Note most of this is temprorary */
  506. #if CALL_NOT_IN_CARBON
  507. EXTERN_API_C( OSStatus )
  508. USBGetConfigurationDescriptor    (USBPB *                pb);
  509.  
  510. EXTERN_API_C( OSStatus )
  511. USBGetFullConfigurationDescriptor (USBPB *                pb);
  512.  
  513. EXTERN_API_C( OSStatus )
  514. USBGetStringDescriptor            (USBPB *                pb);
  515.  
  516. EXTERN_API_C( OSStatus )
  517. USBFindNextEndpointDescriptorImmediate (USBPB *            pb);
  518.  
  519. EXTERN_API_C( OSStatus )
  520. USBFindNextInterfaceDescriptorImmediate (USBPB *        pb);
  521.  
  522. EXTERN_API_C( OSStatus )
  523. USBFindNextAssociatedDescriptor    (USBPB *                pb);
  524.  
  525.  
  526.  
  527. /* Utility functions */
  528. EXTERN_API_C( OSStatus )
  529. USBResetDevice                    (USBPB *                pb);
  530.  
  531. EXTERN_API_C( OSStatus )
  532. USBPortStatus                    (USBPB *                pb);
  533.  
  534. EXTERN_API_C( OSStatus )
  535. USBSuspendDevice                (USBPB *                pb);
  536.  
  537. EXTERN_API_C( OSStatus )
  538. USBResumeDeviceByReference        (USBReference             refIn);
  539.  
  540. #endif  /* CALL_NOT_IN_CARBON */
  541.  
  542. #if CALL_NOT_IN_CARBON
  543. EXTERN_API_C( OSStatus )
  544. USBGetBandwidthAvailableByReference (USBReference         ref,
  545.                                  UInt32 *                avail);
  546.  
  547. #endif  /* CALL_NOT_IN_CARBON */
  548.  
  549. #if CALL_NOT_IN_CARBON
  550. EXTERN_API_C( OSStatus )
  551. USBGetFrameNumberImmediate        (USBPB *                pb);
  552.  
  553. EXTERN_API_C( OSStatus )
  554. USBDelay                        (USBPB *                pb);
  555.  
  556. EXTERN_API_C( OSStatus )
  557. USBSAbortQueuesByReference        (USBReference             ref);
  558.  
  559. EXTERN_API_C( OSStatus )
  560. USBAllocMem                        (USBPB *                pb);
  561.  
  562. EXTERN_API_C( OSStatus )
  563. USBDeallocMem                    (USBPB *                pb);
  564.  
  565. /* Expert interface functions */
  566. EXTERN_API_C( OSStatus )
  567. USBExpertInstallInterfaceDriver    (USBDeviceRef             ref,
  568.                                  USBDeviceDescriptorPtr  desc,
  569.                                  USBInterfaceDescriptorPtr  interfacePtr,
  570.                                  USBReference             hubRef,
  571.                                  UInt32                 busPowerAvailable);
  572.  
  573. EXTERN_API_C( OSStatus )
  574. USBExpertRemoveInterfaceDriver    (USBDeviceRef             ref);
  575.  
  576. EXTERN_API_C( OSStatus )
  577. USBExpertInstallDeviceDriver    (USBDeviceRef             ref,
  578.                                  USBDeviceDescriptorPtr  desc,
  579.                                  USBReference             hubRef,
  580.                                  UInt32                 port,
  581.                                  UInt32                 busPowerAvailable);
  582.  
  583. EXTERN_API_C( OSStatus )
  584. USBExpertRemoveDeviceDriver        (USBDeviceRef             ref);
  585.  
  586. EXTERN_API_C( OSStatus )
  587. USBExpertStatus                    (USBDeviceRef             ref,
  588.                                  void *                    pointer,
  589.                                  UInt32                 value);
  590.  
  591. EXTERN_API_C( OSStatus )
  592. USBExpertFatalError                (USBDeviceRef             ref,
  593.                                  OSStatus                 status,
  594.                                  void *                    pointer,
  595.                                  UInt32                 value);
  596.  
  597. #endif  /* CALL_NOT_IN_CARBON */
  598.  
  599. #if CALL_NOT_IN_CARBON
  600. EXTERN_API_C( OSStatus )
  601. USBExpertNotify                    (void *                    note);
  602.  
  603. #endif  /* CALL_NOT_IN_CARBON */
  604.  
  605. #if CALL_NOT_IN_CARBON
  606. EXTERN_API_C( OSStatus )
  607. USBExpertStatusLevel            (UInt32                 level,
  608.                                  USBDeviceRef             ref,
  609.                                  StringPtr                 status,
  610.                                  UInt32                 value);
  611.  
  612. EXTERN_API_C( UInt32 )
  613. USBExpertGetStatusLevel            (void);
  614.  
  615. EXTERN_API_C( void )
  616. USBExpertSetStatusLevel            (UInt32                 level);
  617.  
  618.  
  619.  
  620. EXTERN_API_C( OSStatus )
  621. USBExpertSetDevicePowerStatus    (USBDeviceRef             ref,
  622.                                  UInt32                 reserved1,
  623.                                  UInt32                 reserved2,
  624.                                  UInt32                 powerStatus,
  625.                                  UInt32                 busPowerAvailable,
  626.                                  UInt32                 busPowerNeeded);
  627.  
  628. #endif  /* CALL_NOT_IN_CARBON */
  629.  
  630. enum {
  631.     kUSBDevicePower_PowerOK        = 0,
  632.     kUSBDevicePower_BusPowerInsufficient = 1,
  633.     kUSBDevicePower_BusPowerNotAllFeatures = 2,
  634.     kUSBDevicePower_SelfPowerInsufficient = 3,
  635.     kUSBDevicePower_SelfPowerNotAllFeatures = 4,
  636.     kUSBDevicePower_HubPortOk    = 5,
  637.     kUSBDevicePower_HubPortOverCurrent = 6,
  638.     kUSBDevicePower_BusPoweredHubOnLowPowerPort = 7,
  639.     kUSBDevicePower_BusPoweredHubToBusPoweredHub = 8,
  640.     kUSBDevicePower_Reserved3    = 9,
  641.     kUSBDevicePower_Reserved4    = 10
  642. };
  643.  
  644.  
  645. /* For hubs only */
  646. #if CALL_NOT_IN_CARBON
  647. EXTERN_API_C( OSStatus )
  648. USBHubAddDevice                    (USBPB *                pb);
  649.  
  650. EXTERN_API_C( OSStatus )
  651. USBHubConfigurePipeZero            (USBPB *                pb);
  652.  
  653. EXTERN_API_C( OSStatus )
  654. USBHubSetAddress                (USBPB *                pb);
  655.  
  656. EXTERN_API_C( OSStatus )
  657. USBHubDeviceRemoved                (USBPB *                pb);
  658.  
  659. EXTERN_API_C( UInt8 )
  660. USBMakeBMRequestType            (UInt8                     direction,
  661.                                  UInt8                     reqtype,
  662.                                  UInt8                     recipient);
  663.  
  664. EXTERN_API_C( OSStatus )
  665. USBControlRequest                (USBPB *                pb);
  666.  
  667. #endif  /* CALL_NOT_IN_CARBON */
  668.  
  669.  
  670. typedef UInt32                             USBLocationID;
  671. enum {
  672.     kUSBLocationNibbleFormat    = 0                                /* Other values are reserved for future types (like when we have more than 16 ports per hub)*/
  673. };
  674.  
  675.  
  676. enum {
  677.     kNoDeviceRef                = -1
  678. };
  679.  
  680. /* Status Level constants*/
  681. /*
  682. Level 1: Fatal errors
  683. Level 2: General errors that may or may not effect operation
  684. Level 3: General driver messages.  The "AddStatus" call that drivers use comes through as a level 3.  This is also the default level at boot time.
  685. Level 4: Important status messages from the Expert and USL.
  686. Level 5: General status messages from the Expert and USL.
  687. */
  688. enum {
  689.     kUSBStatusLevelFatal        = 1,
  690.     kUSBStatusLevelError        = 2,
  691.     kUSBStatusLevelClient        = 3,
  692.     kUSBStatusLevelGeneral        = 4,
  693.     kUSBStatusLevelVerbose        = 5
  694. };
  695.  
  696. /* Expert Notification Types*/
  697.  
  698. typedef UInt8 USBNotificationType;
  699. enum {
  700.     kNotifyAddDevice            = 0x00,
  701.     kNotifyRemoveDevice            = 0x01,
  702.     kNotifyAddInterface            = 0x02,
  703.     kNotifyRemoveInterface        = 0x03,
  704.     kNotifyGetDeviceDescriptor    = 0x04,
  705.     kNotifyGetInterfaceDescriptor = 0x05,
  706.     kNotifyGetNextDeviceByClass    = 0x06,
  707.     kNotifyGetDriverConnectionID = 0x07,
  708.     kNotifyInstallDeviceNotification = 0x08,
  709.     kNotifyRemoveDeviceNotification = 0x09,
  710.     kNotifyDeviceRefToBusRef    = 0x0A,
  711.     kNotifyDriverNotify            = 0x0C,
  712.     kNotifyParentNotify            = 0x0D,
  713.     kNotifyAnyEvent                = 0xFF,
  714.     kNotifyPowerState            = 0x17,
  715.     kNotifyStatus                = 0x18,
  716.     kNotifyFatalError            = 0x19,
  717.     kNotifyStatusLevel            = 0x20
  718. };
  719.  
  720. typedef USBNotificationType             USBDriverMessage;
  721. /*
  722.    USB Manager wildcard constants for USBGetNextDeviceByClass
  723.    and USBInstallDeviceNotification.
  724. */
  725.  
  726. typedef UInt16 USBManagerWildcard;
  727. enum {
  728.     kUSBAnyClass                = 0xFFFF,
  729.     kUSBAnySubClass                = 0xFFFF,
  730.     kUSBAnyProtocol                = 0xFFFF,
  731.     kUSBAnyVendor                = 0xFFFF,
  732.     kUSBAnyProduct                = 0xFFFF
  733. };
  734.  
  735.  
  736.  
  737.  
  738. struct ExpertNotificationData {
  739.     USBNotificationType             notification;
  740.     UInt8                             filler[1];                    /* unused due to 2-byte 68k alignment*/
  741.     USBDeviceRef *                    deviceRef;
  742.     UInt32                             busPowerAvailable;
  743.     void *                            data;
  744.     UInt32                             info1;
  745.     UInt32                             info2;
  746. };
  747. typedef struct ExpertNotificationData    ExpertNotificationData;
  748. typedef ExpertNotificationData *        ExpertNotificationDataPtr;
  749. /* Definition of function pointer passed in ExpertEntryProc*/
  750. typedef CALLBACK_API_C( OSStatus , ExpertNotificationProcPtr )(ExpertNotificationDataPtr pNotificationData);
  751. /* Definition of expert's callback installation function*/
  752. typedef CALLBACK_API_C( OSStatus , ExpertEntryProcPtr )(ExpertNotificationProcPtr pExpertNotify);
  753. /* Device Notification Callback Routine*/
  754. typedef CALLBACK_API_C( void , USBDeviceNotificationCallbackProcPtr )(void *pb);
  755. /* Device Notification Parameter Block*/
  756.  
  757. struct USBDeviceNotificationParameterBlock {
  758.     UInt16                             pbLength;
  759.     UInt16                             pbVersion;
  760.     USBNotificationType             usbDeviceNotification;
  761.     UInt8                             reserved1[1];                /* needed because of 2-byte 68k alignment*/
  762.     USBDeviceRef                     usbDeviceRef;
  763.     UInt16                             usbClass;
  764.     UInt16                             usbSubClass;
  765.     UInt16                             usbProtocol;
  766.     UInt16                             usbVendor;
  767.     UInt16                             usbProduct;
  768.     OSStatus                         result;
  769.     UInt32                             token;
  770.     USBDeviceNotificationCallbackProcPtr  callback;
  771.     UInt32                             refcon;
  772. };
  773. typedef struct USBDeviceNotificationParameterBlock USBDeviceNotificationParameterBlock;
  774. typedef USBDeviceNotificationParameterBlock * USBDeviceNotificationParameterBlockPtr;
  775. /* Definition of USBDriverNotificationCallback Routine*/
  776. typedef CALLBACK_API_C( void , USBDriverNotificationCallbackPtr )(OSStatus status, UInt32 refcon);
  777. /* Public Functions*/
  778. #if CALL_NOT_IN_CARBON
  779. EXTERN_API_C( UInt32 )
  780. USBGetVersion                    (void);
  781.  
  782. EXTERN_API_C( OSStatus )
  783. USBGetNextDeviceByClass            (USBDeviceRef *            deviceRef,
  784.                                  CFragConnectionID *    connID,
  785.                                  UInt16                 theClass,
  786.                                  UInt16                 theSubClass,
  787.                                  UInt16                 theProtocol);
  788.  
  789. EXTERN_API_C( OSStatus )
  790. USBGetDeviceDescriptor            (USBDeviceRef *            deviceRef,
  791.                                  USBDeviceDescriptor *    deviceDescriptor,
  792.                                  UInt32                 size);
  793.  
  794. EXTERN_API_C( OSStatus )
  795. USBGetInterfaceDescriptor        (USBInterfaceRef *        interfaceRef,
  796.                                  USBInterfaceDescriptor * interfaceDescriptor,
  797.                                  UInt32                 size);
  798.  
  799. EXTERN_API_C( OSStatus )
  800. USBGetDriverConnectionID        (USBDeviceRef *            deviceRef,
  801.                                  CFragConnectionID *    connID);
  802.  
  803. EXTERN_API_C( void )
  804. USBInstallDeviceNotification    (USBDeviceNotificationParameterBlock * pb);
  805.  
  806. EXTERN_API_C( OSStatus )
  807. USBRemoveDeviceNotification        (UInt32                 token);
  808.  
  809. EXTERN_API_C( OSStatus )
  810. USBDeviceRefToBusRef            (USBDeviceRef *            deviceRef,
  811.                                  USBBusRef *            busRef);
  812.  
  813. EXTERN_API_C( OSStatus )
  814. USBDriverNotify                    (USBReference             reference,
  815.                                  USBDriverMessage         mesg,
  816.                                  UInt32                 refcon,
  817.                                  USBDriverNotificationCallbackPtr  callback);
  818.  
  819. EXTERN_API_C( OSStatus )
  820. USBExpertNotifyParent            (USBReference             reference,
  821.                                  void *                    pointer);
  822.  
  823. EXTERN_API_C( OSStatus )
  824. USBAddDriverForFSSpec            (USBReference             reference,
  825.                                  FSSpec *                fileSpec);
  826.  
  827. #endif  /* CALL_NOT_IN_CARBON */
  828.  
  829. #if CALL_NOT_IN_CARBON
  830. EXTERN_API_C( OSStatus )
  831. USBAddShimFromDisk                (FSSpec *                shimFilePtr);
  832.  
  833. EXTERN_API_C( OSStatus )
  834. USBReferenceToRegEntry            (RegEntryID *            parentEntry,
  835.                                  USBDeviceRef             parentDeviceRef);
  836.  
  837. #endif  /* CALL_NOT_IN_CARBON */
  838.  
  839. typedef CALLBACK_API_C( void , HIDInterruptProcPtr )(UInt32 refcon, void *theData);
  840. typedef CALLBACK_API_C( void , HIDNotificationProcPtr )(UInt32 refcon, UInt32 reportSize, void *theReport, USBReference theInterfaceRef);
  841. /* HID Install Interrupt prototype*/
  842. typedef CALLBACK_API_C( OSStatus , USBHIDInstallInterruptProcPtr )(HIDInterruptProcPtr pInterruptProc, UInt32 refcon);
  843. /* HID Poll Device prototype*/
  844. typedef CALLBACK_API_C( OSStatus , USBHIDPollDeviceProcPtr )(void );
  845. /* HID Control Device prototype*/
  846. typedef CALLBACK_API_C( OSStatus , USBHIDControlDeviceProcPtr )(UInt32 theControlSelector, void *theControlData);
  847. /* HID Get Device Info prototype*/
  848. typedef CALLBACK_API_C( OSStatus , USBHIDGetDeviceInfoProcPtr )(UInt32 theInfoSelector, void *theInfo);
  849. /* HID Enter Polled Mode prototype*/
  850. typedef CALLBACK_API_C( OSStatus , USBHIDEnterPolledModeProcPtr )(void );
  851. /* HID Exit Polled Mode prototype*/
  852. typedef CALLBACK_API_C( OSStatus , USBHIDExitPolledModeProcPtr )(void );
  853. /* HID Install Notification prototype*/
  854. typedef CALLBACK_API_C( OSStatus , USBHIDInstallNotificationProcPtr )(HIDNotificationProcPtr pNotificationProc, UInt32 refcon);
  855. enum {
  856.     kHIDStandardDispatchVersion    = 0,
  857.     kHIDReservedDispatchVersion    = 1,
  858.     kHIDNotificationDispatchVersion = 2,
  859.     kHIDCurrentDispatchVersion    = 2
  860. };
  861.  
  862.  
  863.  
  864. struct USBHIDRev2DispatchTable {
  865.     UInt32                             hidDispatchVersion;
  866.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  867.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  868.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  869.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  870.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  871.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  872.     USBHIDInstallNotificationProcPtr  pUSBHIDInstallNotification;
  873. };
  874. typedef struct USBHIDRev2DispatchTable    USBHIDRev2DispatchTable;
  875. typedef USBHIDRev2DispatchTable *        USBHIDRev2DispatchTablePtr;
  876.  
  877. struct USBHIDModuleDispatchTable {
  878.     UInt32                             hidDispatchVersion;
  879.     USBHIDInstallInterruptProcPtr     pUSBHIDInstallInterrupt;
  880.     USBHIDPollDeviceProcPtr         pUSBHIDPollDevice;
  881.     USBHIDControlDeviceProcPtr         pUSBHIDControlDevice;
  882.     USBHIDGetDeviceInfoProcPtr         pUSBHIDGetDeviceInfo;
  883.     USBHIDEnterPolledModeProcPtr     pUSBHIDEnterPolledMode;
  884.     USBHIDExitPolledModeProcPtr     pUSBHIDExitPolledMode;
  885. };
  886. typedef struct USBHIDModuleDispatchTable USBHIDModuleDispatchTable;
  887. typedef USBHIDModuleDispatchTable *        USBHIDModuleDispatchTablePtr;
  888. /*    Prototypes Tue, Mar 17, 1998 4:54:30 PM    */
  889. #if CALL_NOT_IN_CARBON
  890. EXTERN_API_C( OSStatus )
  891. USBHIDInstallInterrupt            (HIDInterruptProcPtr     HIDInterruptFunction,
  892.                                  UInt32                 refcon);
  893.  
  894. EXTERN_API_C( OSStatus )
  895. USBHIDPollDevice                (void);
  896.  
  897. EXTERN_API_C( OSStatus )
  898. USBHIDControlDevice                (UInt32                 theControlSelector,
  899.                                  void *                    theControlData);
  900.  
  901. EXTERN_API_C( OSStatus )
  902. USBHIDGetDeviceInfo                (UInt32                 theInfoSelector,
  903.                                  void *                    theInfo);
  904.  
  905. EXTERN_API_C( OSStatus )
  906. USBHIDEnterPolledMode            (void);
  907.  
  908. EXTERN_API_C( OSStatus )
  909. USBHIDExitPolledMode            (void);
  910.  
  911. EXTERN_API_C( OSStatus )
  912. USBHIDInstallNotification        (HIDNotificationProcPtr  HIDNotificationFunction,
  913.                                  UInt32                 refcon);
  914.  
  915. EXTERN_API_C( void )
  916. HIDNotification                    (UInt32                 devicetype,
  917.                                  UInt8                     NewHIDData[],
  918.                                  UInt8                     OldHIDData[]);
  919.  
  920. #endif  /* CALL_NOT_IN_CARBON */
  921.  
  922. enum {
  923.     kHIDRqGetReport                = 1,
  924.     kHIDRqGetIdle                = 2,
  925.     kHIDRqGetProtocol            = 3,
  926.     kHIDRqSetReport                = 9,
  927.     kHIDRqSetIdle                = 10,
  928.     kHIDRqSetProtocol            = 11
  929. };
  930.  
  931. enum {
  932.     kHIDRtInputReport            = 1,
  933.     kHIDRtOutputReport            = 2,
  934.     kHIDRtFeatureReport            = 3
  935. };
  936.  
  937. enum {
  938.     kHIDBootProtocolValue        = 0,
  939.     kHIDReportProtocolValue        = 1
  940. };
  941.  
  942. enum {
  943.     kHIDKeyboardInterfaceProtocol = 1,
  944.     kHIDMouseInterfaceProtocol    = 2
  945. };
  946.  
  947. enum {
  948.     kHIDSetLEDStateByBits        = 1,
  949.     kHIDSetLEDStateByBitMask    = 1,
  950.     kHIDSetLEDStateByIDNumber    = 2,
  951.     kHIDRemoveInterruptHandler    = 3,
  952.     kHIDEnableDemoMode            = 4,
  953.     kHIDDisableDemoMode            = 5,
  954.     kHIDRemoveNotification        = 0x1000
  955. };
  956.  
  957. enum {
  958.     kHIDGetLEDStateByBits        = 1,                            /* not supported in 1.0 of keyboard module*/
  959.     kHIDGetLEDStateByBitMask    = 1,                            /* not supported in 1.0 of keyboard module*/
  960.     kHIDGetLEDStateByIDNumber    = 2,
  961.     kHIDGetDeviceCountryCode    = 3,                            /* not supported in 1.0 HID modules*/
  962.     kHIDGetDeviceUnitsPerInch    = 4,                            /* only supported in mouse HID module*/
  963.     kHIDGetInterruptHandler        = 5,
  964.     kHIDGetCurrentKeys            = 6,                            /* only supported in keyboard HID module*/
  965.     kHIDGetInterruptRefcon        = 7,
  966.     kHIDGetVendorID                = 8,
  967.     kHIDGetProductID            = 9
  968. };
  969.  
  970.  
  971. enum {
  972.     kNumLockLED                    = 0,
  973.     kCapsLockLED                = 1,
  974.     kScrollLockLED                = 2,
  975.     kComposeLED                    = 3,
  976.     kKanaLED                    = 4
  977. };
  978.  
  979. enum {
  980.     kNumLockLEDMask                = 1 << kNumLockLED,
  981.     kCapsLockLEDMask            = 1 << kCapsLockLED,
  982.     kScrollLockLEDMask            = 1 << kScrollLockLED,
  983.     kComposeLEDMask                = 1 << kComposeLED,
  984.     kKanaLEDMask                = 1 << kKanaLED
  985. };
  986.  
  987. enum {
  988.     kUSBCapsLockKey                = 0x39,
  989.     kUSBNumLockKey                = 0x53,
  990.     kUSBScrollLockKey            = 0x47
  991. };
  992.  
  993.  
  994. struct USBMouseData {
  995.     UInt16                             buttons;
  996.     SInt16                             XDelta;
  997.     SInt16                             YDelta;
  998. };
  999. typedef struct USBMouseData                USBMouseData;
  1000. typedef USBMouseData *                    USBMouseDataPtr;
  1001.  
  1002. struct USBKeyboardData {
  1003.     UInt16                             keycount;
  1004.     UInt16                             usbkeycode[32];
  1005. };
  1006. typedef struct USBKeyboardData            USBKeyboardData;
  1007. typedef USBKeyboardData *                USBKeyboardDataPtr;
  1008.  
  1009. union USBHIDData {
  1010.     USBKeyboardData                 kbd;
  1011.     USBMouseData                     mouse;
  1012. };
  1013. typedef union USBHIDData                USBHIDData;
  1014. typedef USBHIDData *                    USBHIDDataPtr;
  1015. #if CALL_NOT_IN_CARBON
  1016. EXTERN_API_C( void )
  1017. StartCompoundClassDriver        (USBDeviceRef             device,
  1018.                                  UInt16                 classID,
  1019.                                  UInt16                 subClass);
  1020.  
  1021. #endif  /* CALL_NOT_IN_CARBON */
  1022.  
  1023. enum {
  1024.     kUSBCompositeClass            = 0,
  1025.     kUSBAudioClass                = 1,
  1026.     kUSBCommClass                = 2,
  1027.     kUSBHIDClass                = 3,
  1028.     kUSBDisplayClass            = 4,
  1029.     kUSBPrintingClass            = 7,
  1030.     kUSBMassStorageClass        = 8,
  1031.     kUSBHubClass                = 9,
  1032.     kUSBDataClass                = 10,
  1033.     kUSBVendorSpecificClass        = 0xFF
  1034. };
  1035.  
  1036. enum {
  1037.     kUSBCompositeSubClass        = 0,
  1038.     kUSBHubSubClass                = 1,
  1039.     kUSBPrinterSubclass            = 1,
  1040.     kUSBVendorSpecificSubClass    = 0xFF
  1041. };
  1042.  
  1043. enum {
  1044.     kUSBHIDInterfaceClass        = 0x03
  1045. };
  1046.  
  1047. enum {
  1048.     kUSBNoInterfaceSubClass        = 0x00,
  1049.     kUSBBootInterfaceSubClass    = 0x01
  1050. };
  1051.  
  1052. enum {
  1053.     kUSBNoInterfaceProtocol        = 0x00,
  1054.     kUSBKeyboardInterfaceProtocol = 0x01,
  1055.     kUSBMouseInterfaceProtocol    = 0x02,
  1056.     kUSBVendorSpecificProtocol    = 0xFF
  1057. };
  1058.  
  1059. enum {
  1060.     kUSBPrinterUnidirectionalProtocol = 0x01,
  1061.     kUSBPrinterBidirectionalProtocol = 0x02
  1062. };
  1063.  
  1064.  
  1065. enum {
  1066.     kServiceCategoryUSB            = FOUR_CHAR_CODE('usb ')        /* USB*/
  1067. };
  1068.  
  1069. enum {
  1070.     kUSBDriverFileType            = FOUR_CHAR_CODE('ndrv'),
  1071.     kUSBDriverRsrcType            = FOUR_CHAR_CODE('usbd'),
  1072.     kUSBShimRsrcType            = FOUR_CHAR_CODE('usbs')
  1073. };
  1074.  
  1075. enum {
  1076.     kTheUSBDriverDescriptionSignature = FOUR_CHAR_CODE('usbd')
  1077. };
  1078.  
  1079. enum {
  1080.     kInitialUSBDriverDescriptor    = 0
  1081. };
  1082.  
  1083.  
  1084.  
  1085. typedef UInt32                             USBDriverDescVersion;
  1086. /*  Driver Loading Options*/
  1087.  
  1088. typedef UInt32 USBDriverLoadingOptions;
  1089. enum {
  1090.     kUSBDoNotMatchGenericDevice    = 0x00000001,                    /* Driver's VendorID must match Device's VendorID*/
  1091.     kUSBDoNotMatchInterface        = 0x00000002,                    /* Do not load this driver as an interface driver.*/
  1092.     kUSBProtocolMustMatch        = 0x00000004,                    /* Do not load this driver if protocol field doesn't match.*/
  1093.     kUSBInterfaceMatchOnly        = 0x00000008                    /* Only load this driver as an interface driver.*/
  1094. };
  1095.  
  1096. enum {
  1097.     kClassDriverPluginVersion    = 0x00001100
  1098. };
  1099.  
  1100.  
  1101.  
  1102.  
  1103. struct USBDeviceInfo {
  1104.     UInt16                             usbVendorID;                /* USB Vendor ID*/
  1105.     UInt16                             usbProductID;                /* USB Product ID.*/
  1106.     UInt16                             usbDeviceReleaseNumber;        /* Release Number of Device*/
  1107.     UInt16                             usbDeviceProtocol;            /* Protocol Info.*/
  1108. };
  1109. typedef struct USBDeviceInfo            USBDeviceInfo;
  1110. typedef USBDeviceInfo *                    USBDeviceInfoPtr;
  1111.  
  1112. struct USBInterfaceInfo {
  1113.     UInt8                             usbConfigValue;                /* Configuration Value*/
  1114.     UInt8                             usbInterfaceNum;            /* Interface Number*/
  1115.     UInt8                             usbInterfaceClass;            /* Interface Class*/
  1116.     UInt8                             usbInterfaceSubClass;        /* Interface SubClass*/
  1117.     UInt8                             usbInterfaceProtocol;        /* Interface Protocol*/
  1118. };
  1119. typedef struct USBInterfaceInfo            USBInterfaceInfo;
  1120. typedef USBInterfaceInfo *                USBInterfaceInfoPtr;
  1121.  
  1122. struct USBDriverType {
  1123.     Str31                             nameInfoStr;                /* Driver's name when loading into the Name Registry.*/
  1124.     UInt8                             usbDriverClass;                /* USB Class this driver belongs to.*/
  1125.     UInt8                             usbDriverSubClass;            /* Module type*/
  1126.     NumVersion                         usbDriverVersion;            /* Class driver version number.*/
  1127. };
  1128. typedef struct USBDriverType            USBDriverType;
  1129. typedef USBDriverType *                    USBDriverTypePtr;
  1130.  
  1131. struct USBDriverDescription {
  1132.     OSType                             usbDriverDescSignature;        /* Signature field of this structure.*/
  1133.     USBDriverDescVersion             usbDriverDescVersion;        /* Version of this data structure.*/
  1134.     USBDeviceInfo                     usbDeviceInfo;                /* Product & Vendor Info*/
  1135.     USBInterfaceInfo                 usbInterfaceInfo;            /* Interface info*/
  1136.     USBDriverType                     usbDriverType;                /* Driver Info.*/
  1137.     USBDriverLoadingOptions         usbDriverLoadingOptions;    /* Options for class driver loading.*/
  1138. };
  1139. typedef struct USBDriverDescription        USBDriverDescription;
  1140. typedef USBDriverDescription *            USBDriverDescriptionPtr;
  1141. /*
  1142.    Dispatch Table
  1143.    Definition of class driver's HW Validation proc.
  1144. */
  1145. typedef CALLBACK_API_C( OSStatus , USBDValidateHWProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1146. /*
  1147.    Definition of class driver's device initialization proc.
  1148.    Called if the driver is being loaded for a device
  1149. */
  1150. typedef CALLBACK_API_C( OSStatus , USBDInitializeDeviceProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  1151. /* Definition of class driver's interface initialization proc.*/
  1152. typedef CALLBACK_API_C( OSStatus , USBDInitializeInterfaceProcPtr )(UInt32 interfaceNum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDevice, USBInterfaceRef interfaceRef);
  1153. /* Definition of class driver's finalization proc.*/
  1154. typedef CALLBACK_API_C( OSStatus , USBDFinalizeProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  1155.  
  1156. typedef UInt32 USBDriverNotification;
  1157. enum {
  1158.     kNotifySystemSleepRequest    = 0x00000001,
  1159.     kNotifySystemSleepDemand    = 0x00000002,
  1160.     kNotifySystemSleepWakeUp    = 0x00000003,
  1161.     kNotifySystemSleepRevoke    = 0x00000004,
  1162.     kNotifyHubEnumQuery            = 0x00000006,
  1163.     kNotifyChildMessage            = 0x00000007,
  1164.     kNotifyExpertTerminating    = 0x00000008,
  1165.     kNotifyDriverBeingRemoved    = 0x0000000B,
  1166.     kNotifyAllowROMDriverRemoval = 0x0000000E
  1167. };
  1168.  
  1169. /*
  1170.    Definition of driver's notification proc.      
  1171.    Added refcon for 1.1 version of dispatch table
  1172. */
  1173. typedef CALLBACK_API_C( OSStatus , USBDDriverNotifyProcPtr )(USBDriverNotification notification, void *pointer, UInt32 refcon);
  1174.  
  1175. struct USBClassDriverPluginDispatchTable {
  1176.     UInt32                             pluginVersion;
  1177.     USBDValidateHWProcPtr             validateHWProc;                /* Proc for driver to verify proper HW*/
  1178.     USBDInitializeDeviceProcPtr     initializeDeviceProc;        /* Proc that initializes the class driver.*/
  1179.     USBDInitializeInterfaceProcPtr     initializeInterfaceProc;    /* Proc that initializes a particular interface in the class driver.*/
  1180.     USBDFinalizeProcPtr             finalizeProc;                /* Proc that finalizes the class driver.*/
  1181.     USBDDriverNotifyProcPtr         notificationProc;            /* Proc to pass notifications to the driver.*/
  1182. };
  1183. typedef struct USBClassDriverPluginDispatchTable USBClassDriverPluginDispatchTable;
  1184. typedef USBClassDriverPluginDispatchTable * USBClassDriverPluginDispatchTablePtr;
  1185. /* Shim Defines*/
  1186. enum {
  1187.     kTheUSBShimDescriptionSignature = FOUR_CHAR_CODE('usbs')
  1188. };
  1189.  
  1190.  
  1191. typedef UInt32 USBShimDescVersion;
  1192. enum {
  1193.     kCurrentUSBShimDescVers        = 0x0100
  1194. };
  1195.  
  1196. /*  Shim Loading Options*/
  1197.  
  1198. typedef UInt32 USBShimLoadingOptions;
  1199. enum {
  1200.     kUSBRegisterShimAsSharedLibrary = 0x00000001                /* Driver's VendorID must match Device's VendorID*/
  1201. };
  1202.  
  1203.  
  1204. struct USBShimDescription {
  1205.     OSType                             usbShimDescSignature;        /* Signature field of this structure.*/
  1206.     USBShimDescVersion                 usbShimDescVersion;            /* Version of this data structure.*/
  1207.     USBShimLoadingOptions             usbDriverLoadingOptions;    /* Options for shim loading.*/
  1208.     Str63                             libraryName;                /* For optional shared library registration*/
  1209. };
  1210. typedef struct USBShimDescription        USBShimDescription;
  1211. typedef USBShimDescription *            USBShimDescriptionPtr;
  1212. /* Hub defines*/
  1213.  
  1214. enum {
  1215.     kUSBHubDescriptorType        = 0x29
  1216. };
  1217.  
  1218. enum {
  1219.                                                                 /* Hub features */
  1220.     kUSBHubLocalPowerChangeFeature = 0,
  1221.     kUSBHubOverCurrentChangeFeature = 1,                        /* port features */
  1222.     kUSBHubPortConnectionFeature = 0,
  1223.     kUSBHubPortEnableFeature    = 1,
  1224.     kUSBHubPortSuspendFeature    = 2,
  1225.     kUSBHubPortOverCurrentFeature = 3,
  1226.     kUSBHubPortResetFeature        = 4,
  1227.     kUSBHubPortPowerFeature        = 8,
  1228.     kUSBHubPortLowSpeedFeature    = 9,
  1229.     kUSBHubPortConnectionChangeFeature = 16,
  1230.     kUSBHubPortEnableChangeFeature = 17,
  1231.     kUSBHubPortSuspendChangeFeature = 18,
  1232.     kUSBHubPortOverCurrentChangeFeature = 19,
  1233.     kUSBHubPortResetChangeFeature = 20
  1234. };
  1235.  
  1236.  
  1237. enum {
  1238.     kHubPortConnection            = 1,
  1239.     kHubPortEnabled                = 2,
  1240.     kHubPortSuspend                = 4,
  1241.     kHubPortOverCurrent            = 8,
  1242.     kHubPortBeingReset            = 16,
  1243.     kHubPortPower                = 0x0100,
  1244.     kHubPortSpeed                = 0x0200
  1245. };
  1246.  
  1247. enum {
  1248.     kHubLocalPowerStatus        = 1,
  1249.     kHubOverCurrentIndicator    = 2,
  1250.     kHubLocalPowerStatusChange    = 1,
  1251.     kHubOverCurrentIndicatorChange = 2
  1252. };
  1253.  
  1254. enum {
  1255.     off                            = false,
  1256.     on                            = true
  1257. };
  1258.  
  1259.  
  1260.  
  1261. struct hubDescriptor {
  1262.                                                                 /* See usbDoc pg 250?? */
  1263.     UInt8                             dummy;                        /* to align charcteristics */
  1264.  
  1265.     UInt8                             length;
  1266.     UInt8                             hubType;
  1267.     UInt8                             numPorts;
  1268.  
  1269.     UInt16                             characteristics;
  1270.     UInt8                             powerOnToGood;                /* Port settling time, in 2ms */
  1271.     UInt8                             hubCurrent;
  1272.  
  1273.                                                                 /* These are received packed, will have to be unpacked */
  1274.     UInt8                             removablePortFlags[8];
  1275.     UInt8                             pwrCtlPortFlags[8];
  1276. };
  1277. typedef struct hubDescriptor            hubDescriptor;
  1278.  
  1279.  
  1280.  
  1281. #if PRAGMA_STRUCT_ALIGN
  1282.     #pragma options align=reset
  1283. #elif PRAGMA_STRUCT_PACKPUSH
  1284.     #pragma pack(pop)
  1285. #elif PRAGMA_STRUCT_PACK
  1286.     #pragma pack()
  1287. #endif
  1288.  
  1289. #ifdef PRAGMA_IMPORT_OFF
  1290. #pragma import off
  1291. #elif PRAGMA_IMPORT
  1292. #pragma import reset
  1293. #endif
  1294.  
  1295. #ifdef __cplusplus
  1296. }
  1297. #endif
  1298.  
  1299. #endif /* __USB__ */
  1300.  
  1301.